package num190;

/**
 * 190. 颠倒二进制位
 * 题目：https://leetcode-cn.com/problems/reverse-bits/
 * 三叶姐题解: https://leetcode-cn.com/problems/reverse-bits/solution/yi-ti-san-jie-dui-cheng-wei-zhu-wei-fen-ub1hi/
 * 三叶姐
 *
 * 分组互换」
 */
public class Solution3 {
    public int reverseBits(int n) {
        n = ((n & 0xAAAAAAAA) >>> 1)  | ((n & 0x55555555) << 1);
        n = ((n & 0xCCCCCCCC) >>> 2)  | ((n & 0x33333333) << 2);
        n = ((n & 0xF0F0F0F0) >>> 4)  | ((n & 0x0F0F0F0F) << 4);
        n = ((n & 0xFF00FF00) >>> 8)  | ((n & 0x00FF00FF) << 8);
        n = ((n & 0xFFFF0000) >>> 16) | ((n & 0x0000FFFF) << 16);
        return n;
    }

    public static void main(String[] args) {
        new Solution3().reverseBits(43261596);
    }
}
